<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+(request.getServerPort() == 80 ? "" : ":" + request.getServerPort()) + path;
request.setAttribute("basePath", basePath);
%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>
		<jsp:include page="/WEB-INF/views/title.jsp" />
	</title>
    <jsp:include page="/WEB-INF/views/head.jsp" />
    <style type="text/css">
    	.page-header .header-buttons a:before{
    		display: none;
    	}
    </style>
</head>
<body>
	<!-- Loading Container -->
    <div class="loading-container">
        <div class="loading-progress">
            <div class="rotator">
                <div class="rotator">
                    <div class="rotator colored">
                        <div class="rotator">
                            <div class="rotator colored">
                                <div class="rotator colored"></div>
                                <div class="rotator"></div>
                            </div>
                            <div class="rotator colored"></div>
                        </div>
                        <div class="rotator"></div>
                    </div>
                    <div class="rotator"></div>
                </div>
                <div class="rotator"></div>
            </div>
            <div class="rotator"></div>
        </div>
    </div>
    <!--  /Loading Container -->
    <jsp:include page="/WEB-INF/views/nav.jsp"></jsp:include>
    <!-- Main Container -->
    <div class="main-container container-fluid">
        <!-- Page Container -->
        <div class="page-container">
            <!-- Page Sidebar -->
            <div class="page-sidebar" id="sidebar">
                <!-- Sidebar Menu -->
                <ul class="nav sidebar-menu">
                	<c:forEach var="menu" items="${menus}">
                		<shiro:hasPermission name="${menu.perm}">
	                	<li>
                		<c:choose>
                			<c:when test="${fn:length(menu.children) >0}">
                				<a href="javascript:void(0);" class="menu-dropdown">
		                            <i class="menu-icon ${menu.icon}"></i>
		                            <span class="menu-text"> ${menu.name} </span>
		                            <i class="menu-expand"></i>
		                        </a>
		                        <ul class="submenu">
		                        	<c:forEach var="submenu" items="${menu.children}">
		                        		<shiro:hasPermission name="${submenu.perm}">
		                        		<li>
			                                <a href="${submenu.url}" target="iframe">
			                                    <span class="menu-text"> ${submenu.name} </span>
			                                </a>
			                            </li>	
			                            </shiro:hasPermission>
		                        	</c:forEach>
		                        </ul>
                			</c:when>
                			<c:otherwise>
		                        <a href="${menu.url}">
		                            <i class="menu-icon ${menu.icon}"></i>
		                            <span class="menu-text"> ${menu.name} </span>
		                        </a>
                			</c:otherwise>
                		</c:choose>
                		</li>
                		</shiro:hasPermission>
                	</c:forEach>
                </ul>
                <!-- /Sidebar Menu -->
            </div>
            <!-- /Page Sidebar -->
            <!-- Page Content -->
            <div class="page-content">
                <!-- Page Breadcrumb -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb">
                        <li>
                            <i class="fa fa-dashboard"></i>
                            <a href="javascript:void(0);">工作台</a>
                        </li>
                        <li>
                            <a href="javascript:void(0);">后台首页</a>
                        </li>
                    </ul>
                </div>
                <!-- /Page Breadcrumb -->
                <!-- Page Header -->
                <div class="page-header">
                    <div class="header-title">
                        <h1 id="menuTitle"> 后台首页 </h1>
                    </div>
                    <div class="header-buttons">
                        <a class="sidebar-toggler" href="javascript:void(0);">
                            <i class="fa fa-arrows-h"></i>
                        </a>
                        <a class="refresh" id="refresh-toggler" href="javascript:reloadFrame();">
                            <i class="glyphicon glyphicon-refresh"></i>
                        </a>
                        <a class="fullscreen" id="fullscreen-toggler" href="javascript:void(0);">
                            <i class="glyphicon glyphicon-fullscreen"></i>
                        </a>
                    </div>
                </div>
                <!-- /Page Header -->
                <!-- Page Body -->
                <div class="page-body">
                    <!-- Your Content Goes Here -->
                    <iframe src="/admin/dashboard/welcome" name="iframe" id="iframe" scrolling="no" style="border:0;width: 100%;" onload="iframeOnload(this);" onerror="iframeOnload(this);"></iframe>
                </div>
                <!-- /Page Body -->
            </div>
            <!-- /Page Content -->
        </div>
        <!-- /Page Container -->
        <!-- Main Container -->
    </div>
    <!--Basic Scripts-->
    <script src="${ctx}/static/beyond/js/jquery-2.0.3.min.js"></script>
    <script src="${ctx}/static/beyond/js/bootstrap.min.js"></script>

    <!--Beyond Scripts-->
    <script src="${ctx}/static/beyond/js/beyond.min.js"></script>
    <script type="text/javascript">
    	function iframeOnload(iframe) {
			if (iframe) {
				$(".loading-container").addClass("loading-inactive");
				$("#sidebar").removeClass("hide").removeClass("menu-compact");
			}
		}
		function reloadFrame(){
			var iframe = $("#iframe")[0];
			var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
			iframeWin.location.reload();
		}
		$(function(){
			$("#sidebar li a").not($("#sidebar li a").has(".menu-expand")).click(function(e){
				e.preventDefault();
				$("#sidebar li").removeClass("active");
				$(this).parent("li").addClass("active");
				var text = $(this).text().trim();
				var parent = $(this).parent("li").parent("ul.submenu").prev("a");
				var parentIcon = parent.children("i.menu-icon").clone().removeClass("menu-icon");
				var parentText = parent.text().trim();
				$("#menuTitle").text(text);
				$(".page-breadcrumbs ul.breadcrumb").empty();
				$(".page-breadcrumbs ul.breadcrumb").append($("<li/>").append(parentIcon).append($("<a href='javascript:void(0);'/>").text(parentText)));
				$(".page-breadcrumbs ul.breadcrumb").append($("<li/>").append($("<a href='javascript:void(0);'/>").text(text)));
				
				try{$(window.frames["iframe"].document.body).empty();}catch(ex){}
				
				$("#iframe").attr("src", this.href);
				$(".loading-container").removeClass("loading-inactive");
			});
			var frameInterval = setInterval(function(){
				var iframe = $("#iframe")[0];
				iframe.height = $(window.frames["iframe"].document.body).height();
				//var iframeWin = iframe.contentWindow || iframe.contentDocument.parentWindow;
				//window.location.hash = iframeWin.location.toString().replace("${basePath}","");
				//if (iframeWin.document.body) {
				//	iframe.style.height = (iframeWin.document.documentElement.offsetHeight || iframeWin.document.body.offsetHeight) + "px";
				//}
			}, 200);
		});
    </script>
</body>
</html>
